<?php
class Mem
{
	private $type='Memcached';//数据库类型
	private $m;//对象
	private $time=0;//存储时间
	private $error;//错误信息
	private $debug=false;//调试模式

	public function __construct()
	{
		if(!class_exists($this->type)){
			$this->error='Class '.$this->type.' not found';
			return false;
		}else{
			$this->m=new $this->type;
		}
	}

	public function addServers($arr)
	{
		$this->m->addServers($arr);
	}

	public function S($key,$value='',$time=NULl)
	{
		$number=func_num_args();//获取函数参数数量
		if($number==1){//get
			return $this->get($key);
		}elseif($number>=2){
			if($value===NULl){//delete
				$this->delete($key);
			}else{//set
				$this->set($key,$value,$time);
			}
		}
	}

	private function set($key,$value,$time)
	{
		if($time===NULl)$time=$this->time;
		if($this->type=='Memcached'&&is_array($key)){//多数据操作
			$this->m->setMulti($key,$value);
		}else{
			$this->m->set($key,$value,$time);
		}
	}

	private function get($key)
	{
		if($this->type='Memcached'&&is_array($key)){//多数据操作
			return $this->m->getMulti($key);
		}else{
			return $this->m->get($key);
		}
	}

	private function delete($key)
	{
		if($this->type='Memcached'&&is_array($key)){//多数据操作
			return $this->m->deleteMulti($key);
		}else{
			return $this->m->delete($key);
		}
	}

	//错误处理
	public function getError()
	{
		if(!$this->debug)return;//调试模式
		if($this->error){
			return $this->error;
		}else{
			return $this->m->getResultMessage();
		}
	}
}